package com.assetmanage.utils;

import io.minio.BucketExistsArgs;
import io.minio.MinioClient;

public class MinioConfig {
    // MinIO服务器地址
    private static final String ENDPOINT = "http://127.0.0.1:9000";
    // MinIO访问密钥（Access Key）
    private static final String ACCESS_KEY = "minioadmin";
    // MinIO密钥（Secret Key）
    private static final String SECRET_KEY = "minioadmin";
    // 默认存储桶名称
    private static final String DEFAULT_BUCKET = "assetmanage";

    private static MinioClient minioClient;

    public static MinioClient getMinioClient() {
        if (minioClient == null) {
            try {
                minioClient = MinioClient.builder()
                        .endpoint(ENDPOINT)
                        .credentials(ACCESS_KEY, SECRET_KEY)
                        .build();
                
                // 测试连接是否成功
                minioClient.bucketExists(BucketExistsArgs.builder()
                        .bucket(DEFAULT_BUCKET)
                        .build());
                
                System.out.println("成功连接到MinIO服务器");
            } catch (Exception e) {
                System.err.println("无法连接到MinIO服务器: " + e.getMessage());
                System.err.println("请确保MinIO服务器已启动，并且配置正确");
                System.err.println("MinIO服务器地址: " + ENDPOINT);
                throw new RuntimeException("MinIO服务器连接失败", e);
            }
        }
        return minioClient;
    }

    public static String getDefaultBucket() {
        return DEFAULT_BUCKET;
    }
} 